<?php

abstract class APlugin
{

	protected $options;
	protected $view;
	protected $plugin;
	protected $tpl;
	protected $ns;
	protected $config;

	function __construct(){}

	abstract public function display();

	public function show()
	{
		echo $this->display();
	}

	public function init($in_plugin_name)
	{
		$this->plugin = ucfirst($in_plugin_name);
		$this->plugin_id = strtolower($in_plugin_name);
		$this->tpl = AFramework::get()->view();
		$this->ns = $this->plugin_id."_plugin_";
		$this->plugin_uri = AFramework::get()->getConfig('site web root').'plugin/'.$in_plugin_name.'/';
		$this->assign('uri',$this->plugin_uri);

		$this->view = 'plugin_default.tpl';
	}

	public function getPath($item,$use_pdir=true)
	{
		return (($use_pdir) ? PLUGIN_DIR : '').ucfirst($this->plugin)."/".$item;
	}

	public function getTemplate()
	{
		return $this->getPath("templates/".$this->view,false);
	}

	public function setTemplate($in_view)
	{
		$this->view = $in_view;
	}

	public function getOption($in_opt)
	{
		return ((isset($this->options[$in_opt])) ? $this->options[$in_opt] : null);
	}

	public function setOption($in_opt, $in_val=null)
	{
		if (!is_null($in_val))
			return $this->options[$in_opt] = $in_val;
		unset($this->options[$in_opt]);
	}

	public function assign($var,$val)
	{
		$this->tpl->assign($this->ns.$var,$val);
	}

	public function assignRef($var,&$val)
	{
		$this->tpl->assignRef($this->ns.$var,$val);
	}

}

?>